package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.PageResponseResult;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.NewsAuthDto;
import com.heima.media.dto.WmNewsDto;
import com.heima.media.dto.WmNewsPageDto;
import com.heima.media.dto.WmNewsVo;
import com.heima.media.entity.WmNews;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmNewsService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author mcm
 * @since 2022-06-22
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
public class WmNewsController{

    @Autowired
    private IWmNewsService wmNewsService;

    /**
     * 客户端：自媒体分页查询
     */
    @PostMapping("/list")
    public ResponseResult listByPage(@RequestBody WmNewsPageDto dto){
        return wmNewsService.listByPage(dto);
    }
    /**
     * 自媒体文章-发布/修改/保存文稿
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto){
        return wmNewsService.submit(wmNewsDto);
    }
    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public ResponseResult getById(@PathVariable Integer id){
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }
    /**
     * 文章上架下架
     */
    @PostMapping("/down_or_up")
    public ResponseResult changeEnable(@RequestBody WmNewsDto dto){
       return wmNewsService.changeEnable(dto);
    }
    /**
     * 自媒体端查询列表
     */
    @PostMapping("/findPageByName")
    public PageResponseResult<List<WmNewsVo>> findPageByName(@RequestBody NewsAuthDto dto){
        return wmNewsService.findPageByName(dto);
    }
    /**
     * 自媒体端查看列表详情
     */
    @GetMapping("/findNewsVoById/{id}")
    public ResponseResult<WmNewsVo> findNewsVoById(@PathVariable Long id){
        return wmNewsService.findNewsVoById(id);
    }
    /**
     * 人工审核：通过
     */
    @PostMapping("/auth_pass")
    public ResponseResult auth_pass(@RequestBody NewsAuthDto dto){
        return wmNewsService.auth(dto,1);
    }
    /**
     * 人工审核：不通过
     */
    @PostMapping("/auth_fail")
    public ResponseResult auth_fail(@RequestBody NewsAuthDto dto){
        return wmNewsService.auth(dto,0);
    }



}
